/**
 * 
 */
package org.mspring.mlog.web.freemarker.directive;

import java.io.IOException;
import java.util.Map;

import org.mspring.mlog.utils.UploadUtils;
import org.mspring.mlog.utils.WebUtils;
import org.mspring.platform.utils.StringUtils;
import org.mspring.platform.web.freemarker.DirectiveUtils;
import org.mspring.platform.web.freemarker.directive.AbstractDirectiveModel;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

/**
 * @author Gao Youbo
 * @since 2013-6-4
 * @description
 * @TODO 获取图片的展示URL
 */
public class PhotoUrlDirectiveModel extends AbstractDirectiveModel {

    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Override
    public void execute(Environment env, Map params, TemplateModel[] model, TemplateDirectiveBody body) throws TemplateException, IOException {
        // TODO Auto-generated method stub
        String url = DirectiveUtils.getString("url", params);
        if (StringUtils.isNotBlank(url)) {
            url = WebUtils.getContextPath() + UploadUtils.UPLOAD_FOLDER + url;
            env.getOut().append(url);
        }
    }

}
